﻿@using Model.Admin;
@using Xproject.Util;
@{
    string Domain = CommonHelper.GetAppSettings("Domin");
    Layout = null;
}
@*<script src="~/Scripts/Ztree/js/jquery-1.4.4.min.js"></script>*@
<script src="~/Scripts/jquery-2.1.4.min.js"></script>
<script src="~/Scripts/Ztree/js/jquery.ztree.core.js"></script>
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<link href="~/Scripts/Ztree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" />
<script src="~/Scripts/Ztree/js/jquery.ztree.excheck.js"></script>
<script src="~/Scripts/plugins/layer/layer.min.js"></script>
<script type="text/javascript">

    var setting = {
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        }
    };
    var zNodes = eval("[" + "@Html.Raw(ViewBag.ztreeJson)" + "]");



    $(document).ready(function () {
        setting.check.chkboxType = { "Y": "ps", "N": "ps" };
        $.fn.zTree.init($("#treeDemo"), setting, zNodes);
    });
    function UpdateRoleMenus() {
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
        nodes = treeObj.getCheckedNodes(true);
        var selectMenuId = new Array();
        for (var i = 0; i < nodes.length ; i++) {
            selectMenuId.push(nodes[i].id);
        }
        if (nodes.length <= 0) {
            layer.alert("没有为角色设置菜单，很可怕", { icon: 1, skin: 'layer-ext-moon', time: 2000 });
            return;
        }

        $.ajax({
            type: "POST",
            url: '@(Domain)/System/EditRoleMenus',
            data: { menuIds: selectMenuId, roleId: $("#ViewBagroleId").val() },
            cache: false,

            success: function (data) {
                layer.alert(data.Data, { icon: 1, skin: 'layer-ext-moon', time: 2000 });
            }
        });

    }
</script>
<div class="gray-bg">
    <div class=" animated fadeInRight">
        <div class="row" style="height:300px;overflow:auto">
            <div class="col-sm-12">
                <div class="zTreeDemoBackground left">
                    <ul id="treeDemo" class="ztree"></ul>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12" style="text-align:center">
                <input type="hidden" id="ViewBagroleId" value="@ViewBag.roleId" />
                <button class="btn btn-primary" onclick="UpdateRoleMenus();">确认设置</button>
            </div>
        </div>
    </div>
</div>